import React, { Component } from 'react';
import Topnav from '@/components/Topnav'

class Index extends Component {
    state = {
        num:5
    }
    timer = null
    componentDidMount(){
        this.timer && clearInterval(this.timer)
        this.timer = setInterval(() => {
            this.setState(state => ({ num:state.num - 1 }))
            if(this.state.num <= 0){
                this.props.history.replace('/home')
            }
        },1000)
    }
    componentWillUnmount(){
        this.timer && clearInterval(this.timer)
    }
    render() {
        return (
            <div>
                <Topnav title="页面丢失" leftText="返回" onLeft={ () =>this.props.history.replace('/home')  } />
                <h3>页面走丢啦...</h3>
                <h3>{this.state.num}</h3>
            </div>
        );
    } 
}

export default Index;
